class_name HoldGunBatDart
extends BaseHoldItem

var shooted: bool = false
@onready var shoot_start_point: Marker2D = $Marker2D
@onready var sprite: Sprite2D = $Sprite


func use():
	if shooted: 
		var player = holder as Player
		player.clear_item_cooldown_timer()
		return
	
	sprite.visible = false
	shooted = true
	var player = holder as Player
	var config = item_data.item_config as ItemThrowWeaponConfig
	var bullet_inst = (ResourceManager.get_resource("bullet_bat_dart") as PackedScene).instantiate() as BulletBatDart
	player.level.bullets_parent.add_child(bullet_inst)
	bullet_inst.global_position = shoot_start_point.global_position
	bullet_inst.sender = player
	bullet_inst.hold_item = self
	bullet_inst.attack = config.attack + player.player_data.get_attack()
	bullet_inst.critical_rate = config.critical_rate
	bullet_inst.critical_bonus = config.critical_bonus
	bullet_inst.knockback = config.knockback
	bullet_inst.shoot_dir = Vector2.from_angle(player.gun_hand.global_rotation)


func on_bat_dart_returned():
	sprite.visible = true
	shooted = false
